/*!
 * \file tt_frconfig_del_string.c
 *
 * All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.\n
 *
 * \version 3.0
 * \author geyh
 * \date 2016/03/31
 *
 */
#include <CUnit/Basic.h>
#include <stdlib.h>

#include "frcomm.h"
#include "frmem.h"
#include "frconfig.h"
#include "conntrack.h"
#include "frct_comm.h"

#include "apmtest_comm.h"

static int __suite_init(void)
{

    return 0;
}

static int __suite_cleanup(void)
{

    return 0;
}

static void __case1(void)
{
    int i_ret = 0;

    i_ret = frconfig_del_string((char *)"t_frconfig/t_frconfig_del_string/test9.txt",(char *)"time",NULL);
    CU_ASSERT_EQUAL(i_ret,FR_FAIL);

    return;
}

static void __case2(void)
{
    int i_ret = 0;

    i_ret = frconfig_del_string((char *)"t_frconfig/t_frconfig_del_string/test9.txt",NULL,(char *)"10");
    CU_ASSERT_EQUAL(i_ret,FR_FAIL);

    return;
}

static void __case3(void)
{
    int i_ret = 0;

    i_ret = frconfig_del_string(NULL,(char *)"time",(char *)"10");
    CU_ASSERT_EQUAL(i_ret,FR_FAIL);

    return;
}

static void __case4(void)
{
    int i_ret = 0;
    char *p_value = NULL;

    system("cp t_frconfig/t_frconfig_del_string/test4.txt t_frconfig/t_frconfig_del_string/test.txt");

    i_ret = frconfig_del_string((char *)"t_frconfig/t_frconfig_del_string/test.txt",(char *)"time",(char *)"10");
    CU_ASSERT_EQUAL(i_ret,FR_SUCC);
    system("cp t_frconfig/t_frconfig_del_string/test.txt t_frconfig/t_frconfig_del_string/case4.txt");

    frconfig_get_string((char *)"t_frconfig/t_frconfig_del_string/test.txt",(char *)"time",&p_value);
    CU_ASSERT_PTR_NULL(p_value);
    frfree(p_value);
    return;
}

static void __case5(void)
{
    int i_ret = 0;
    char *p_value = NULL;

    system("cp t_frconfig/t_frconfig_del_string/test5.txt t_frconfig/t_frconfig_del_string/test.txt");

    i_ret = frconfig_del_string((char *)"t_frconfig/t_frconfig_del_string/test.txt",(char *)"time",(char *)"10");
    CU_ASSERT_EQUAL(i_ret,FR_SUCC);
    system("cp t_frconfig/t_frconfig_del_string/test.txt t_frconfig/t_frconfig_del_string/case5.txt");

    frconfig_get_string((char *)"t_frconfig/t_frconfig_del_string/test.txt",(char *)"time",&p_value);
    CU_ASSERT_PTR_NULL(p_value);
    frfree(p_value);
    return;
}

static void __case6(void)
{
    int i_ret = 0;
    char *p_value = NULL;

    system("cp t_frconfig/t_frconfig_del_string/test6.txt t_frconfig/t_frconfig_del_string/test.txt");

    i_ret = frconfig_del_string((char *)"t_frconfig/t_frconfig_del_string/test.txt",(char *)"time",(char *)"10");
    CU_ASSERT_EQUAL(i_ret,FR_SUCC);
    system("cp t_frconfig/t_frconfig_del_string/test.txt t_frconfig/t_frconfig_del_string/case6.txt");

    frconfig_get_string((char *)"t_frconfig/t_frconfig_del_string/test.txt",(char *)"time",&p_value);
    CU_ASSERT_PTR_NULL(p_value);
    frfree(p_value);
    return;
}

static void __case7(void)
{
    int i_ret = 0;
    char *p_value = NULL;
    char *p_tmp = (char *)"10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";

    system("cp t_frconfig/t_frconfig_del_string/test7.txt t_frconfig/t_frconfig_del_string/test.txt");

    i_ret = frconfig_del_string((char *)"t_frconfig/t_frconfig_del_string/test.txt",(char *)"time",(char *)"10");
    CU_ASSERT_EQUAL(i_ret,FR_FAIL);
    system("cp t_frconfig/t_frconfig_del_string/test.txt t_frconfig/t_frconfig_del_string/case7.txt");

    frconfig_get_string((char *)"t_frconfig/t_frconfig_del_string/test.txt",(char *)"time",&p_value);
    CU_ASSERT_STRING_EQUAL(p_value,p_tmp);
    frfree(p_value);
    return;
}

static void __case8(void)
{
    int i_ret = 0;
    char *p_value = NULL;

    system("cp t_frconfig/t_frconfig_del_string/test8.txt t_frconfig/t_frconfig_del_string/test.txt");

    i_ret = frconfig_del_string((char *)"t_frconfig/t_frconfig_del_string/test.txt",(char *)"time",(char *)"10");
    CU_ASSERT_EQUAL(i_ret,FR_SUCC);
    system("cp t_frconfig/t_frconfig_del_string/test.txt t_frconfig/t_frconfig_del_string/case8.txt");

    frconfig_get_string((char *)"t_frconfig/t_frconfig_del_string/test.txt",(char *)"time",&p_value);
    CU_ASSERT_PTR_NULL(p_value);
    frfree(p_value);
    return;
}

static void __case9(void)
{
    int i_ret = 0;
    char *p_value = NULL;

    system("cp t_frconfig/t_frconfig_del_string/test9.txt t_frconfig/t_frconfig_del_string/test.txt");

    i_ret = frconfig_del_string((char *)"t_frconfig/t_frconfig_del_string/test.txt",(char *)"time",(char *)"10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");
    CU_ASSERT_EQUAL(i_ret,FR_SUCC);
    system("cp t_frconfig/t_frconfig_del_string/test.txt t_frconfig/t_frconfig_del_string/case9.txt");

    frconfig_get_string((char *)"t_frconfig/t_frconfig_del_string/test.txt",(char *)"time",&p_value);
    CU_ASSERT_PTR_NULL(p_value);
    return;
}

static void __case10(void)
{
    int i_ret = 0;
    char *p_value = NULL;

    system("cp t_frconfig/t_frconfig_del_string/test10.txt t_frconfig/t_frconfig_del_string/test.txt");

    i_ret = frconfig_del_string((char *)"t_frconfig/t_frconfig_del_string/test.txt",(char *)"timetimetimetimetimetimetimetimetimetimetimetimetimetimetimetimetimetimetimetimetimetimetimetimetimetimetimetimetimetimetimetime",(char *)"10");
    CU_ASSERT_EQUAL(i_ret,FR_SUCC);
    system("cp t_frconfig/t_frconfig_del_string/test.txt t_frconfig/t_frconfig_del_string/case10.txt");

    frconfig_get_string((char *)"t_frconfig/t_frconfig_del_string/test.txt",(char *)"timetimetimetimetimetimetimetimetimetimetimetimetimetimetimetimetimetimetimetimetimetimetimetimetimetimetimetimetimetimetimetime",&p_value);
    CU_ASSERT_PTR_NULL(p_value);
    return;
}

static void __case11(void)
{
    int i_ret = 0;
    char *p_value = NULL;

    system("cp t_frconfig/t_frconfig_del_string/test11.txt t_frconfig/t_frconfig_del_string/test.txt");

    i_ret = frconfig_del_string((char *)"t_frconfig/t_frconfig_del_string/test.txt",(char *)"age",(char *)"10");
    CU_ASSERT_EQUAL(i_ret,FR_FAIL);
    system("cp t_frconfig/t_frconfig_del_string/test.txt t_frconfig/t_frconfig_del_string/case11.txt");

    frconfig_get_string((char *)"t_frconfig/t_frconfig_del_string/test.txt",(char *)"time",&p_value);
    CU_ASSERT_STRING_EQUAL(p_value,"10");
    frfree(p_value);
    return;
}

int add_suite_t_frconfig_del_string(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite("frcomm t_frconfig_del_string()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    CU_add_test(pSuite, "case1", __case1);
    CU_add_test(pSuite, "case2", __case2);
    CU_add_test(pSuite, "case3", __case3);
    CU_add_test(pSuite, "case4", __case4);
    CU_add_test(pSuite, "case5", __case5);
    CU_add_test(pSuite, "case6", __case6);
    CU_add_test(pSuite, "case7", __case7);
    CU_add_test(pSuite, "case8", __case8);
    CU_add_test(pSuite, "case9", __case9);
    CU_add_test(pSuite, "case10", __case10);
    CU_add_test(pSuite, "case11", __case11);

    return FR_SUCC;
}
